The present invention generally relates to computer programming, including substitution of character strings. The invention relates more specifically to transforming character strings that are contained in a unit of code.
In general, computer programs or software applications include some sort of user interface mechanism that allows a user to interact with the software application. Many software applications include a graphical user interface (GUI), such as a menu interface system, which enhances the user""s ability to interact with the application software. For example, a user of a bank teller machine typically is presented with several different menu interface windows. Each menu generally includes one or more options that allow the user to enter information and to perform a particular transaction.
To provide a more xe2x80x9cuser-friendlyxe2x80x9d program, a graphical user interface generally includes visual information that describes the different options that may be performed through the user interface. In this context, visual information includes any set of characters or symbols that have been combined in a particular manner to present certain information to the user. For example, a menu interface for a bank teller machine may include the visual information xe2x80x9cENTER YOUR PIN NUMBERxe2x80x9d to inform the user to first enter a personal identification number (PIN) to access their account. Alternatively, a window for a word processing application may include a menu interface that contains the visual information xe2x80x9cFilexe2x80x9d, xe2x80x9cEditxe2x80x9d, xe2x80x9cViewxe2x80x9d and xe2x80x9cFormatxe2x80x9d to inform the user that certain pull-down menus are available for manipulating the contents of a document.
In general, visual information in a user interface is based on the symbols and language that is most familiar to the typical end user. For example, if a bank teller machine is located in the United States, the user interface typically will include visual information that is in English. Alternatively, if a bank teller machine is located in Germany, the user interface will include visual information that is in German.
One approach for generating a user interface that includes visual information is by xe2x80x9chard codingxe2x80x9d character strings throughout the computer program code that generates the user interface. A character string or xe2x80x9cstringxe2x80x9d is a sequence of alphanumeric characters. In many computer programming languages, strings may be stored in discrete named storage locations that may be manipulated as a unit, or may be inserted literally in expressions that are defined, in the grammar of the language, as capable of receiving string parameters. As an example, to generate a user interface that requests a user to enter a username and password when attempting to access an application program, the string xe2x80x9cEnter your Username and Passwordxe2x80x9d may be hard coded into a display routine of the user interface code. To generate a user interface that includes an accept and a reject button on a user interface, the strings xe2x80x9cACCEPTxe2x80x9d and xe2x80x9cREJECTxe2x80x9d may be hard coded into the user interface code.
The hard coding approach has a significant disadvantage; it is inflexible. Changing visual information requires changing the source code of the program that generates the visual information, recompiling it, and re-deploying it to end users. Errors are easily introduced in this process. Unfortunately, hard coding has been used in many software applications that are currently in use. Some applications include thousands or millions of lines of code. As a result, a significant problem with software applications that include hard coded character strings is that a huge amount of time and resources may be required to update or modify the user interface.
For example, if the application includes hard coded character strings throughout the code that provide a user interface in which the visual information is in Japanese, a significant amount of time and resources will be required to convert the visual information to English. In particular, because a string may contain any combination or number of Japanese characters, to convert the user interface to English, a software developer generally must manually search each file to locate each hard coded string. Upon locating each string, the developer must then manually convert the string to English. Once the developer has identified and translated all of the strings, the code must be recompiled and relinked to generate a new executable program.
However, to verify that all of the hard coded strings were properly translated, after building the new executable, the developer must physically view each interface to verify the strings were correctly translated to English. In addition, if the developer determines that a string was not properly translated, the developer must repeat this process to locate the string and to generate a new executable. In a program that has hundreds of different menus that are linked together, it can be extremely difficult for the developer to view and verify each and every interface that may be presented to an end user.
Translation of foreign language content is not the only problem that may arise in a computer program having hard-coded character strings. Any change in the content of the character strings requires a similar, time-consuming revision process that may result in the introduction of new errors.
Consistency is another issue. When a computer program uses the same message in the form of several hard coded strings that are used in different parts of the program, a programmer may revise one string without revising other strings that represent other instances of the same message. As a result, the program will produce inconsistent output.
Based on the foregoing, there is a need for a method or mechanism that can automatically translate hard coded visual information from one language to another.
There is also a need for a method or mechanism that can address the known disadvantages of using hard coded strings in computer programs.
The foregoing needs and objects, and other needs and objects that will become apparent from the following disclosure, are fulfilled by the present invention, which comprises, in one aspect, a method for transforming character strings that are contained in a unit of code, the method comprising the steps of identifying a hard coded string that is contained in the computer program; replacing the string with a macro that is uniquely associated with the string; creating and storing an entry in a mapping that defines an association of the macro and the string; and referencing the mapping in a program element that is associated with the computer program.
According to another feature of this aspect, the step of identifying a string further comprises the steps of identifying one or more computer programs that contain one or more hard coded strings; and parsing one of the computer programs to identify the hard coded strings while copying instructions from the one of the computer programs to an output.
In yet another feature of this aspect, the step of identifying a string further includes the steps of parsing a computer program to locate hard coded strings contained therein; and in response to locating a string, determining whether a macro was previously generated for the string; and generating a corresponding macro uniquely associated with the string only when a macro was not previously generated.
According to another feature, the method further comprises the step of compiling the computer program to generate an executable, including substituting the string in the executable for each instance of the unique macro string in the computer program.
According to yet another feature, the method further comprises the steps of parsing a computer program to locate hard coded strings contained therein; creating and storing a mapping of macros to strings characters; in response to locating a string, determining whether a macro was previously generated for the string by searching the mapping; and generating a corresponding macro uniquely associated with the string only when a macro was not previously generated.
In other aspects, the invention encompasses a computer apparatus and a computer-readable medium configured to carry out the foregoing steps.